package com.onpositive.dataminer.core;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;

import com.onpositive.dataminer.value.audits.WikiLinksRedirectionAudit;
import com.onpositive.knowledge.model.value.audits.ActualDocumentsAudit;
import com.onpositive.knowledge.model.value.audits.BasicValuesAudit;
import com.onpositive.knowledge.model.value.audits.ComparableValueAudit;
import com.onpositive.knowledge.model.value.audits.CompositeAudit;
import com.onpositive.knowledge.model.value.audits.ContradictionsDetectionAudit;
import com.onpositive.knowledge.model.value.audits.DisambiguationValueAudit;
import com.onpositive.knowledge.model.value.audits.IAudit;
import com.onpositive.knowledge.model.value.audits.IdentAudit;
import com.onpositive.knowledge.model.value.audits.IdentValueSplitterAudit;
import com.onpositive.knowledge.model.value.audits.PredictionAudit;
import com.onpositive.knowledge.model.value.audits.ReferenceResolvingAudit;
import com.onpositive.knowledge.model.value.audits.RefsAudit;
import com.onpositive.knowledge.model.value.audits.RefsCounterAudit;
import com.onpositive.knowledge.model.value.audits.StatisticValueAudit;
import com.onpositive.knowledge.model.value.audits.ValueSequenceOrderingAudit;
import com.onpositive.knowledge.model.value.audits.WikiLinksStatisticAudit;


public class DefaultAuditFabric {
	
	public static IAudit getAudit( String ID )
	{		
		DefaultAuditFabric fabric = new DefaultAuditFabric() ;
		return fabric.costructObject(ID) ;		
	}

	
	private HashMap<String,Constructor<?>> map = new HashMap<String, Constructor<?>>() ;
	{
		try {
			map.put( ActualDocumentsAudit.ID, ActualDocumentsAudit.class.getConstructor() ) ;
//			map.put( AllPropertiesAudit.ID, AllPropertiesAudit.class.getConstructor() ) ; requires IUniverse as an argument
//			map.put( AuditManager.ID, AuditManager.class.getConstructor() ) ;
			map.put( ReferenceResolvingAudit.ID, ReferenceResolvingAudit.class.getConstructor() ) ;
			map.put( CompositeAudit.ID, CompositeAudit.class.getConstructor() ) ;
			map.put( IdentValueSplitterAudit.ID, IdentValueSplitterAudit.class.getConstructor() ) ;
			map.put( PredictionAudit.ID, PredictionAudit.class.getConstructor() ) ;
			map.put( ValueSequenceOrderingAudit.ID, ValueSequenceOrderingAudit.class.getConstructor() ) ;
			map.put( WikiLinksStatisticAudit.ID, WikiLinksStatisticAudit.class.getConstructor() ) ;
			map.put( WikiLinksRedirectionAudit.ID, WikiLinksRedirectionAudit.class.getConstructor() ) ;
			
			map.put( BasicValuesAudit.ID, BasicValuesAudit.class.getConstructor() ) ;
			
			map.put( ComparableValueAudit.ID, ComparableValueAudit.class.getConstructor() ) ;
			map.put( RefsAudit.ID, RefsAudit.class.getConstructor() ) ;
			map.put( RefsCounterAudit.ID, RefsCounterAudit.class.getConstructor() ) ;
			map.put( StatisticValueAudit.ID, StatisticValueAudit.class.getConstructor() ) ;
			//map.put( ValueCounterAudit.ID, ValueCounterAudit.class.getConstructor() ) ;
			
			map.put( ContradictionsDetectionAudit.ID, ContradictionsDetectionAudit.class.getConstructor() ) ;
			map.put( DisambiguationValueAudit.ID, DisambiguationValueAudit.class.getConstructor() ) ;
			map.put( IdentAudit.ID, IdentAudit.class.getConstructor() ) ;
			map.put( IsInterestingThingAudit.ID, IsInterestingThingAudit.class.getConstructor() ) ;
			map.put( PropertyRateAudit.ID, PropertyRateAudit.class.getConstructor() ) ;
			
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
	}
	
	private IAudit costructObject(String ID)
	{
		Constructor<?> constr = map.get(ID) ;
		if( constr == null )
			return null ;
		
		try {
			Object obj = constr.newInstance() ;
			
			if( !(obj instanceof IAudit) )
				return null ;
			
			return (IAudit) obj ;
			
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null ;
	}
}
